package DAO;

import Interfaces.IFindStore_Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.proteanit.sql.DbUtils;

public class FindStore_Dao implements IFindStore_Dao {

    @Override
    public boolean findStore(String StoreName) throws IllegalArgumentException {
        boolean finder;
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pst = null;
        try {
            conn = javaconnect.connectDB();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FindStore_Dao.class.getName()).log(Level.SEVERE, null, ex);
        }
        String query = "SELECT * FROM stores WHERE storename=? ";
        try {
            pst = conn.prepareStatement(query);
            pst.setString(1, StoreName);
            rs = pst.executeQuery();

            if (rs.next()) {
                finder = true;
            } else {
                finder = false;
            }

            pst.close();
            conn.close();
            rs.close();
        } catch (SQLException e) {
            throw new IllegalArgumentException("Error in Login_Dao");
        }
        return finder;
    }
    
        public void printFindStores(String StoreName) throws IllegalArgumentException {
        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement pst = null;
        try {
            conn = javaconnect.connectDB();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(FindStore_Dao.class.getName()).log(Level.SEVERE, null, ex);
        }

        String query = "SELECT StoreName  FROM stores WHERE StoreName=?";
        try {
            pst = conn.prepareStatement(query);
            pst.setString(1, StoreName);
            rs = pst.executeQuery();
            Frames.FindStore_Frame.SearchTable.setModel(DbUtils.resultSetToTableModel(rs));

            pst.close();
            conn.close();
            rs.close();

        } catch (SQLException e) {
            throw new IllegalArgumentException("Error in PrintStores_Dao ");
        }
    }
}
